function BeClient() {
  this.defualtOptions = {
    preloaderShow: true,
    preloaderHide: true,
    timeout: 60000
  },
  this.loadSettings = function(responseStatus) {
    APP.currencyEuro = parseFloat(responseStatus.currencyEuro);
  },
  this.onSuccess = function(data, options, method, callback) {
    if (options.preloaderHide)
      APP.hidePreloader();
    APP.User.setData(data.response.responseStatus.user);

    if (callback != undefined)
      callback.obj[callback.name](data.response, options);
    var globalCallback = method + 'Success';
    if (this[globalCallback] !== undefined)
      this[globalCallback](data.response, options);
  },
  this.onError = function(data, callback, options) {
    if (callback != undefined)
      callback.obj[callback.name](data, options);
    if (data.responseJSON !== undefined) {
      var params = {
        name: data.responseJSON.response.exception.actionParam,
        message: data.responseJSON.response.exception.messageForUser
      }
      switch (data.responseJSON.response.exception.actionType) {
        case 'redirect':
          params.obj = router;
          break;
        default:
          params.obj = null;
          break;
      }
    } else {
      var params = {
        name: 'asd',
        message: UNDEFINED_ERROR_MESSAGE,
        obj: null
      }
    }
    new APP.Views.DialogErrorView(params).render();
  },
  this.invoke = function (method, params, callbackSuccess, callbackError, options) {
    if (typeof options == "undefined")
      var options = {};
    options = $.extend({}, this.defualtOptions, options);
    var self = this;
    $.ajax({
      type: 'POST',
      url: ADDRESS_BE + method,
      cache: false,
      data: {
        'params': params
      },
      dataType: "json",
      async: true,  
      timeout: options.timeout,
      beforeSend: function () {
        if (options.preloaderShow)
          APP.showPreloader();
      },
      success: function(data) {
        self.onSuccess(data, options, method, callbackSuccess);
      },
      error: function(data, textStatus) {
        self.onError(data, callbackError, options);
      }
    });
  },
  this.getApp = function() {
    var app = new Object();
    app.ip = IP;
    app.lang = lang;
    return app;
  },
  this.getMenuData = function(callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    this.invoke('get.menu.data', u, callbackSuccess, callbackError, options);
  },
  this.saveOrder = function(order, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.order = order;
    this.invoke('save.order', u, callbackSuccess, callbackError, options);
  },
  this.hideApp = function(applicationId, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.applicationId = applicationId;
    this.invoke('hide.app', u, callbackSuccess, callbackError, options);
  },
  this.getUserPulpitApp = function(applicationId, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.applicationId = applicationId;
    this.invoke('get.user.pulpit.app', u, callbackSuccess, callbackError, options);
  },
  this.getUserPulpitList = function(callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    this.invoke('get.user.pulpit.list', u, callbackSuccess, callbackError, options);
  },
  this.saveUserPulpit = function(applicationId, data, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.applicationId = applicationId;
    u.data = data;
    this.invoke('save.user.pulpit', u, callbackSuccess, callbackError, options);
  },
  this.saveUserPulpitVisibilities = function(applicationIds, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.applicationIds = applicationIds;
    this.invoke('save.user.pulpit.visibilities', u, callbackSuccess, callbackError, options);
  }
  this.getUserData = function(callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    this.invoke('get.user.data', u, callbackSuccess, callbackError, options);
  },
  this.getUserList = function(callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    this.invoke('get.user.list', u, callbackSuccess, callbackError, options);
  },
  this.getUserGroupList = function(callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    this.invoke('get.user.group.list', u, callbackSuccess, callbackError, options);
  },
  this.setActive = function(userId, active, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.userId = userId;
    u.active = active;
    this.invoke('set.active', u, callbackSuccess, callbackError, options);
  },
  this.setUserGroup = function(userId, groupId, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.userId = userId;
    u.groupId = groupId;
    this.invoke('set.user.group', u, callbackSuccess, callbackError, options);
  },
  this.getUserGroupApplications = function(callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    this.invoke('get.user.group.applications', u, callbackSuccess, callbackError, options);
  },
  this.setGroupApplication = function(userGroupId, applicationId, action, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.userGroupId = userGroupId;
    u.applicationId = applicationId;
    u.action = action;
    this.invoke('set.group.application', u, callbackSuccess, callbackError, options);
  },
  this.addUserGroup = function(name, nameEn, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.name = name;
    u.nameEn = nameEn;
    this.invoke('add.user.group', u, callbackSuccess, callbackError, options);
  },
  this.removeUserGroup = function(userGroupId, callbackSuccess, callbackError, options) {
    var u = new Object();
    u.app = this.getApp();
    u.userGroupId = userGroupId;
    this.invoke('remove.user.group', u, callbackSuccess, callbackError, options);
  }
}